package com.jeecms.cms.manager.assist.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeecms.cms.dao.assist.CmsFlashlogoDao;
import com.jeecms.cms.entity.assist.CmsFlashlogo;
import com.jeecms.cms.manager.assist.CmsFlashlogoMng;
import com.jeecms.common.hibernate3.Updater;

@Service
@Transactional
public class CmsFlashlogoMngImpl implements CmsFlashlogoMng {
	@Transactional(readOnly = true)
	public List<CmsFlashlogo> getList(Boolean enabled) {
		List<CmsFlashlogo> list = dao.getList(enabled);
		return list;
	}

	@Transactional(readOnly = true)
	public CmsFlashlogo findById(Integer id) {
		CmsFlashlogo entity = dao.findById(id);
		return entity;
	}

	public CmsFlashlogo save(CmsFlashlogo bean) {
		dao.save(bean);
		return bean;
	}

	public CmsFlashlogo update(CmsFlashlogo bean) {
		Updater<CmsFlashlogo> updater = new Updater<CmsFlashlogo>(bean);
		bean = dao.updateByUpdater(updater);
		return bean;
	}

	public void updatePriority(Integer[] ids, Integer[] priorities) {
		if (ids == null || priorities == null || ids.length <= 0
				|| ids.length != priorities.length) {
			return;
		}
		CmsFlashlogo link;
		for (int i = 0, len = ids.length; i < len; i++) {
			link = findById(ids[i]);
			link.setPriority(priorities[i]);
		}

	}

	public CmsFlashlogo deleteById(Integer id) {
		CmsFlashlogo bean = dao.deleteById(id);
		return bean;
	}

	public CmsFlashlogo[] deleteByIds(Integer[] ids) {
		CmsFlashlogo[] beans = new CmsFlashlogo[ids.length];
		for (int i = 0, len = ids.length; i < len; i++) {
			beans[i] = deleteById(ids[i]);
		}
		return beans;
	}

	private CmsFlashlogoDao dao;

	@Autowired
	public void setDao(CmsFlashlogoDao dao) {
		this.dao = dao;
	}
}